﻿using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace 测试连线2
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            // 模拟一些节点和连线数据
            var node1 = new CircuitNode(100, 100, "Node1");
            var node2 = new CircuitNode(300, 200, "Node2");
            var connection = new CircuitConnection(node1, node2);
            // 绘制连线
            //DrawConnection(connection);


            DrawComplexConnection(connection);
        }
        private void DrawConnection(CircuitConnection connection)
        {
            // 创建一个 Line 元素
            var line = new Line
            {
                X1 = connection.StartNode.X,
                Y1 = connection.StartNode.Y,
                X2 = connection.EndNode.X,
                Y2 = connection.EndNode.Y,
                Stroke = Brushes.Black,
                StrokeThickness = 2
            };
            // 将 Line 元素添加到 Canvas 中
            DrawingCanvas.Children.Add(line);
        }


        private void DrawComplexConnection(CircuitConnection connection)
        {
            // 创建一个 Path 元素
            var path = new Path
            {
                Stroke = Brushes.Black,
                StrokeThickness = 2
            };

            // 创建一个 PathGeometry
            var pathGeometry = new PathGeometry();
            var pathFigure = new PathFigure
            {
                StartPoint = new Point(connection.StartNode.X, connection.StartNode.Y),
                IsClosed = false
            };

            // 这里可以添加多个 LineSegment 或 BezierSegment 来实现复杂连线
            var lineSegment = new LineSegment
            {
                Point = new Point(connection.EndNode.X, connection.EndNode.Y)
            };
            pathFigure.Segments.Add(lineSegment);
            pathGeometry.Figures.Add(pathFigure);

            path.Data = pathGeometry;

            // 将 Path 元素添加到 Canvas 中
            DrawingCanvas.Children.Add(path);
        }
    }
}